<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="v1/include/header_bus :: all_head(xx维护)">
</head>
<body>
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1 th:replace="v1/include/header_bus :: all_t_h(xx列表)"></h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 系统管理</a></li>
        <li class="active">xx管理</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <div class="box">
        <div class="box-header">

            <button class="btn btn-success btn-sm" id="addPermission"><i class="fa fa-plus"></i> &nbsp;&nbsp;添加xx</button>
        </div>
        <!-- /.box-header -->
        <div class="box-body">
            <table id="permissionList" class="table table-bordered table-striped" data-striped="true"
                  >
                <thead>
                <tr>
                    <th>序号</th>
                                <th>菜单名称</th>
                                <th>父菜单id</th>
                                <th>菜单排序</th>
                                <th>权限分类（0 菜单；1 功能）</th>
                                <th>描述</th>
                                <th>菜单编号</th>
                                <th>菜单图标名称</th>
                                <th>菜单url</th>
                                <th>添加时间</th>
                                <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="entity,stat :${page.entityList}">
                    <td th:text="${stat.count}">1</td>
                                <td th:text="${entity.name}">菜单名称</td>
                                <td th:text="${entity.pid}">父菜单id</td>
                                <td th:text="${entity.zindex}">菜单排序</td>
                                <td th:text="${entity.istype}">权限分类（0 菜单；1 功能）</td>
                                <td th:text="${entity.descpt}">描述</td>
                                <td th:text="${entity.code}">菜单编号</td>
                                <td th:text="${entity.icon}">菜单图标名称</td>
                                <td th:text="${entity.page}">菜单url</td>
                        <td>
                            <span th:if="${entity.insertTime !=null}"  th:text="${#dates.format(entity.insertTime,'yyyy-MM-dd')}">添加时间
                        </span>
                        </td>
                        <td>
                            <span th:if="${entity.updateTime !=null}"  th:text="${#dates.format(entity.updateTime,'yyyy-MM-dd')}">更新时间
                        </span>
                        </td>
                <td>
                    <div>
                            <span data-toggle="tooltip" title="编辑xx信息" class="btn btn-xs btn-info"
                                  th:onclick="'editPermission(\''+${entity.id}+'\');'">
                                <i class="fa fa-edit"></i> 编辑</span>

                        <span data-toggle="tooltip" title="删除xx" class="btn btn-xs btn-danger"
                              th:onclick="'delPermission(\''+${entity.id}+'\');'"><i
                                class="fa fa-trash-o"></i> 删除</span>
                    </div>
                    <div>
                        <span><i class="fa fa-lock"></i></span>
                    </div>
                </td>
                </tbody>
            </table>
            <!---分页工具条-->
            <div id="pagination" class="col-sm-2"></div>
        </div>


    </div>
</section>

<!-- 新增或修改的模态框 -->
<div class="modal fade" id="permissionModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;
                </button>
                <h4 class="modal-title text-center" id="permissionmodelHead">添加xx</h4>
            </div>
            <div class="modal-body">

                <input type="hidden" name="page_permission_url" value=""/>
                <input type="hidden" name="type" value=""/>

                <form id="add_edit_form" class="form-horizontal" role="form">
                        <input type="hidden" name="id" value=""/>
                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label">菜单名称</label>
                        <div class="col-sm-10">
                                    <input type="text" class="form-control" name="name" value="" id="name"
                                           placeholder="请输入菜单名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="pid" class="col-sm-2 control-label">父菜单id</label>
                        <div class="col-sm-10">
                                    <input type="text" class="form-control" name="pid" value="" id="pid"
                                           placeholder="请输入父菜单id">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="zindex" class="col-sm-2 control-label">菜单排序</label>
                        <div class="col-sm-10">
                                    <input type="text" class="form-control" name="zindex" value="" id="zindex"
                                           placeholder="请输入菜单排序">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="istype" class="col-sm-2 control-label">权限分类（0 菜单；1 功能）</label>
                        <div class="col-sm-10">
                                    <input type="text" class="form-control" name="istype" value="" id="istype"
                                           placeholder="请输入权限分类（0 菜单；1 功能）">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="descpt" class="col-sm-2 control-label">描述</label>
                        <div class="col-sm-10">
                                    <input type="text" class="form-control" name="descpt" value="" id="descpt"
                                           placeholder="请输入描述">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="code" class="col-sm-2 control-label">菜单编号</label>
                        <div class="col-sm-10">
                                    <input type="text" class="form-control" name="code" value="" id="code"
                                           placeholder="请输入菜单编号">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="icon" class="col-sm-2 control-label">菜单图标名称</label>
                        <div class="col-sm-10">
                                    <input type="text" class="form-control" name="icon" value="" id="icon"
                                           placeholder="请输入菜单图标名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="page" class="col-sm-2 control-label">菜单url</label>
                        <div class="col-sm-10">
                                    <input type="text" class="form-control" name="page" value="" id="page"
                                           placeholder="请输入菜单url">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="insertTime" class="col-sm-2 control-label">添加时间</label>
                        <div class="col-sm-10">
                                <input type="date" class="form-control" name="insertTime" value="" id="insertTime"
                                       placeholder="请输入添加时间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="updateTime" class="col-sm-2 control-label">更新时间</label>
                        <div class="col-sm-10">
                                <input type="date" class="form-control" name="updateTime" value="" id="updateTime"
                                       placeholder="请输入更新时间">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
                <button type="submit" class="btn btn-success" id="imgSubmit">确定</button>
            </div>
        </div>
    </div>
</div>

<div th:replace="v1/include/header_bus :: all_js"></div>

<script th:inline="javascript">

$(function () {
        //提示框
     $("[data-toggle='tooltip']").tooltip();

    //分页工具条设置
    var options = {
        bootstrapMajorVersion:1,
        currentPage: [[ ${page.number}+1]],//当前页数
        totalPages: [[ ${page.totalPages}==0?1:  ${page.totalPages}]],//总页数
        numberOfPages:5,    //最多显示Page页
        size:"normal" ,//设置控件的显示大小，是个字符串. 允许的值: mini, small, normal,large。值：mini版的、小号的、正常的、大号的。
        itemTexts: function(type, page, current) { //修改显示文字
            switch (type) {
                case "first":
                    return "首页";
                case "prev":
                    return "上一页";
                case "next":
                    return "下一页";
                case "last":
                    return "末页";
                case "page":
                    return page;
            }
        },
        pageUrl: function(type, page, current){
            return "/business/permission/page?page="+page;
        }
    };
    $("#pagination").bootstrapPaginator(options);

    //添加按钮方法
    $("#addPermission").click(function () {
        reloadModelData("/business/permission/add", "添加xx", "添加",null,"add");
        $("#permissionModal").modal("show");
    });

    //确认按钮
    $("#imgSubmit").click(function () {
        var _page_permission_url = $("input[name='page_permission_url']").val();
        var _type = $("input[name='type']").val();
        var _id = $("input[name='id']").val();
        var _name = $("input[name='name']").val();
        var _pid = $("input[name='pid']").val();
        var _zindex = $("input[name='zindex']").val();
        var _istype = $("input[name='istype']").val();
        var _descpt = $("input[name='descpt']").val();
        var _code = $("input[name='code']").val();
        var _icon = $("input[name='icon']").val();
        var _page = $("input[name='page']").val();
        var _insertTime = $("input[name='insertTime']").val();
        var _updateTime = $("input[name='updateTime']").val();
        var _data;
        _data={
                id: _id,
                            name: _name,
                            pid: _pid,
                            zindex: _zindex,
                            istype: _istype,
                            descpt: _descpt,
                            code: _code,
                            icon: _icon,
                            page: _page,
                            insertTime: _insertTime,
                            updateTime: _updateTime };


        //验证非空
        //        if (_type == 'add') {
        //            if (!checkAccount(_bianh, _xingm, _mim)) {
        //                return false;
        //            }
        //        }

        $.ajax({
            type: "post",
            url: _page_permission_url,
            cache: false,
            dataType: "json",
            data: _data,
            success: function (data) {
                var code = data.code || data.result.code;
                var msg = data.msg || data.result.msg;
                if (code == '1') {
                    $("#permissionModal").modal("hide");
                    method.msg_pro("更新成功！",1000,function () {
                        window.location.href = window.location.href;
                    });
                } else {
                    method.msg_alert("提示", msg);
                }
            },
            error:function (data) {
                var msg = data.msg || data.result.msg;
                method.msg_alert("提示", msg);
            }
        });
    });
});




//删除xx
function delPermission(Id) {
    method.msg_confirm("提示","你确定要删除此xx吗？",function(){
        $.ajax({
            type:"POST",
            url:"/business/permission/del",
            dataType:"json",
            data:{id:Id},
            cache:false,
            success:function(data){
                var code = data.code || data.result.code;
                var msg = data.msg || data.result.msg;
                if(code== '1'){
                    method.msg_pro("删除成功！",1000,function () {
                        window.location.href = window.location.href;
                    });
                }else{
                    method.msg_alert("提示", msg);
                }
            },
            error:function (data) {
                var msg = data.msg || data.result.msg;
                method.msg_alert("提示", msg);
            }
        });
    });
}
//编辑xx
function editPermission(Id) {

    $.ajax({
        type:"POST",
        url:"/business/permission/get",
        dataType:"json",
        data:{id:Id},
        cache:false,
        success:function(data){
            var code = data.code || data.result.code;
            var msg = data.msg || data.result.msg;
            if(code== '1'){
                reloadModelData("/business/permission/edit", "编辑xx", "更新",data.resultObject, "edit");
                $("#permissionModal").modal("show");
            }else{
                method.msg_alert("提示", msg);
            }
        },
        error:function (data) {
            var msg = data.msg || data.result.msg;
            method.msg_alert("提示", msg);
        }
    });
}

////验证数据
//function checkAccount(bianh, xingm, password) {
//    if (bianh == '') {
//        $("input[name='bianh']").focus();
//        alert("登录名不能为空");
//        return false;
//    }
//    return true;
//}
//加载模态框的数据
function reloadModelData(url,title,btntext,data,type) {
    $("#permissionModal #permissionmodelHead").text(title);
    $("#permissionModal #imgSubmit").text(btntext);
    $("input[name='page_permission_url']").val(url);
    $("input[name='type']").val(type);

    if(data !=null && data !="" && type == "edit")
    {
                $("input[name='id']").val(data.id);
                $("input[name='name']").val(data.name);
                $("input[name='pid']").val(data.pid);
                $("input[name='zindex']").val(data.zindex);
                $("input[name='istype']").val(data.istype);
                $("input[name='descpt']").val(data.descpt);
                $("input[name='code']").val(data.code);
                $("input[name='icon']").val(data.icon);
                $("input[name='page']").val(data.page);
                $("input[name='insertTime']").val(new Date(data.insertTime).Format("yyyy-MM-dd"));
                $("input[name='updateTime']").val(new Date(data.updateTime).Format("yyyy-MM-dd"));
        //设置是否可编辑
        $("input[name='id']").attr("disabled", true);
    }else{
        //清空界面上的内容
        $("input[name='id']").val("");
        $("input[name='name']").val("");
        $("input[name='pid']").val("");
        $("input[name='zindex']").val("");
        $("input[name='istype']").val("");
        $("input[name='descpt']").val("");
        $("input[name='code']").val("");
        $("input[name='icon']").val("");
        $("input[name='page']").val("");
        $("input[name='insertTime']").val("");
        $("input[name='updateTime']").val("");
        //设置是否可编辑
        $("input[name='id']").attr("disabled", false);
    }
}
</script>
</body>
</html>